#ifndef __SYSTEM_H__
#define __SYSTEM_H__

/// <summary>
/// Includes
/// </summary>
#include <wchar.h>
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/kernel.h>
#include <linux/limits.h>
#include <linux/ioctl.h>
#include <linux/fs.h>

/// <summary>
/// Types
/// </summary>
typedef __kernel_key_t KEY;
typedef __kernel_pid_t PID;
typedef __kernel_pid_t TID;
typedef __kernel_uid_t UID;
typedef __kernel_gid_t GID;

/// <summary>
/// System Errors
/// </summary>
#define	SYS_OK 0
#define SYS_ERROR -1
#define SYS_NOACCESS -4

/// <summary>
/// Runtime Pipeline
/// </summary>
int GetRuntimeFile(wchar_t *path, size_t len);
//int GetRuntimePath();

/// <summary>
/// Terminal Pipeline
/// </summary>
int TerminalOpen(void);
int TerminalGetRows(void);

/// <summary>
/// Process Pipeline
/// </summary>
PID GetProcessID(void);
PID GetParentProcessID(void);
PID GetProcessGroupID(PID pid);

/// <summary>
/// Group Pipeline
/// </summary>
GID GetGroupID(void);

/// <summary>
/// User Pipeline
/// </summary>
UID GetUserID(void);
int SetCurrentUserID(UID uid);

int GetDiskCount(void);

/// <summary>
/// Filesystem Macros
/// </summary>
#define	LOCK_SH 1       // Shared lock.
#define	LOCK_EX	2       // Exclusive lock.
#define	LOCK_UN	8       // Unlock.
#define	LOCK_NB	4       // Don't block when locking.
#define FILE_BEGIN 0    // Seek from beginning of file.
#define FILE_CURRENT 1  // Seek from current position.
#define FILE_END 2      // Seek from end of file.

/// <summary>
/// Filesystem Pipeline
/// </summary>
int CreateDir(const wchar_t *path, int mode);
int Open(const wchar_t *path, int flags, int mode);
int IoControl(int handle, unsigned int command, void *data);
int GetFileAttribute(int handle, const char *name, void *value, int size);
int SetFileAttribute(int handle, const char *name, const void *value, int size, int flags);
int SetOwner(const wchar_t *path, UID uid, GID gid);
int Write(int handle, const void *buffer, int count);
int Read(int handle, void *buffer, int count);
int Seek(int handle, int offset, int whence);
int DeleteDirectory(const wchar_t *path);
int FileUnlock(int handle);
int FileLock(int handle);
int Duplicate(int handle);
int Close(int handle);

/// <summary>
/// System Pipeline
/// </summary>
int GetDomainName(char *name, int len);
int GetMachineName(char *name, int len);
int SetDomainName(const char *name, int len);
int SetMachineName(const wchar_t *name, int len);

#endif